/**
 * VYPe11 Project
 * VYPe11 language compiler.
 * Authors: Jozef Lang (xlangj01), 
 * 			Zoltan Zemko (xzemko01)
 * 2011
 */
package cz.vutbr.fit.VYPe.team18.VYPe11.nodes;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;

import cz.vutbr.fit.VYPe.team18.VYPe11.exception.SematicException;
import cz.vutbr.fit.VYPe.team18.VYPe11.sematic.TACcounter;
import cz.vutbr.fit.VYPe.team18.VYPe11.sematic.declared.DeclarationLevels;

public abstract class Node {
	protected static BufferedWriter tacWriter = null;
	protected static TACcounter tacCounter = null;

	protected static DeclarationLevels declarationLevels = new DeclarationLevels();

	public DeclarationLevels getDeclarationLevels() {
		return declarationLevels;
	}

	public void generateTACtoFile(String fileName) throws IOException, SematicException {
		// open file for writing TAC code
		FileWriter fw = new FileWriter(fileName);
		tacWriter = new BufferedWriter(fw);

		// generate TAC code
		tacCounter = new TACcounter();
		generateTAC();

		// close file
		tacWriter.close();
		tacWriter = null;
	}

	public abstract void generateTAC() throws IOException;
	
	protected void writeTAC(String operation, String op1, String op2, String result) throws IOException {
		tacWriter.write("("+operation+", "+op1+", "+op2+", "+result+")\n");	
	}
}
